home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / srcuc.zip / PROSFILE.C < prev    next >
C/C++ Source or Header  |  1992-04-14  |  5KB  |  132 lines

  1. /* -*-C-*-
  2.  
  3. $Header: /scheme/src/microcode/RCS/prosfile.c,v 1.4 1992/04/14 18:36:17 jinx Exp $
  4.  
  5. Copyright (c) 1987-1992 Massachusetts Institute of Technology
  6.  
  7. This material was developed by the Scheme project at the Massachusetts
  8. Institute of Technology, Department of Electrical Engineering and
  9. Computer Science.  Permission to copy this software, to redistribute
  10. it, and to use it for any purpose is granted, subject to the following
  11. restrictions and understandings.
  12.  
  13. 1. Any copy made of this software must include this copyright notice
  14. in full.
  15.  
  16. 2. Users of this software agree to make their best efforts (a) to
  17. return to the MIT Scheme project any improvements or extensions that
  18. they make, so that these may be included in future releases; and (b)
  19. to inform MIT of noteworthy uses of this software.
  20.  
  21. 3. All materials developed as a consequence of the use of this
  22. software shall duly acknowledge such use, in accordance with the usual
  23. standards of acknowledging credit in academic research.
  24.  
  25. 4. MIT has made no warrantee or representation that the operation of
  26. this software will be error-free, and MIT is under no obligation to
  27. provide any services, by way of maintenance, update, or otherwise.
  28.  
  29. 5. In conjunction with products arising from the use of this material,
  30. there shall be no use of the name of the Massachusetts Institute of
  31. Technology nor of any adaptation thereof in any advertising,
  32. promotional, or sales literature without prior written consent from
  33. MIT in each case. */
  34.  
  35. /* Primitives to perform I/O to and from files. */
  36.  
  37. #include "scheme.h"
  38. #include "prims.h"
  39. #include "osfile.h"
  40.  
  41. extern Tchannel EXFUN (arg_channel, (int));
  42.  
  43. #ifndef OPEN_FILE_HOOK
  44. #define OPEN_FILE_HOOK(channel)
  45. #endif
  46.  
  47. #define OPEN_FILE_PRIMITIVE(OS_open_file)                \
  48. {                                    \
  49.   PRIMITIVE_HEADER (1);                            \
  50.   {                                    \
  51.     Tchannel channel = (OS_open_file (STRING_ARG (1)));            \
  52.     OPEN_FILE_HOOK (channel);                        \
  53.     PRIMITIVE_RETURN (long_to_integer (channel));            \
  54.   }                                    \
  55. }
  56.  
  57. DEFINE_PRIMITIVE ("FILE-OPEN-INPUT-CHANNEL", Prim_file_open_input_channel, 1, 1,
  58.   "Open an input file called FILENAME, returning a channel number.")
  59.   OPEN_FILE_PRIMITIVE (OS_open_input_file)
  60.  
  61. DEFINE_PRIMITIVE ("FILE-OPEN-OUTPUT-CHANNEL", Prim_file_open_output_channel, 1, 1,
  62.   "Open an output file called FILENAME, returning a channel number.\n\
  63. If the file exists, it is rewritten.")
  64.   OPEN_FILE_PRIMITIVE (OS_open_output_file)
  65.  
  66. DEFINE_PRIMITIVE ("FILE-OPEN-BINARY-INPUT-CHANNEL", Prim_file_open_binary_input_channel, 1, 1,
  67.   "Open an input file called FILENAME, in binary mode, returning a channel number.")
  68.   OPEN_FILE_PRIMITIVE (OS_open_load_file)
  69.  
  70. DEFINE_PRIMITIVE ("FILE-OPEN-BINARY-OUTPUT-CHANNEL", Prim_file_open_binary_output_channel, 1, 1,
  71.   "Open an output file called FILENAME, in binary mode,\n\
  72. returning a channel number.  If the file exists, it is rewritten.")
  73.   OPEN_FILE_PRIMITIVE (OS_open_dump_file)
  74.  
  75. DEFINE_PRIMITIVE ("FILE-OPEN-IO-CHANNEL", Prim_file_open_io_channel, 1, 1,
  76.   "Open a file called FILENAME, returning a channel number.\n\
  77. The file is opened for both input and output.\n\
  78. If the file exists, its contents are not disturbed.")
  79.   OPEN_FILE_PRIMITIVE (OS_open_io_file)
  80.  
  81. DEFINE_PRIMITIVE ("FILE-OPEN-APPEND-CHANNEL", Prim_file_open_append_channel, 1, 1,
  82.   "Open an output file called FILENAME, returning a channel number.\n\
  83. If the file exists, output is appended to its contents.")
  84.   OPEN_FILE_PRIMITIVE (OS_open_append_file)
  85.  
  86. DEFINE_PRIMITIVE ("FILE-OPEN-CHANNEL", Prim_file_open_channel, 2, 2,
  87.   "This is an obsolete primitive.\n\
  88. Open a file called FILENAME, returning a channel number.\n\
  89. Second argument MODE says how to open the file:\n\
  90.   #F        ==> open for input;\n\
  91.   #T        ==> open for output, rewriting file if it exists;\n\
  92.   otherwise ==> open for output, appending to existing file.")
  93. {
  94.   PRIMITIVE_HEADER (2);
  95.   {
  96.     CONST char * filename = (STRING_ARG (1));
  97.     fast SCHEME_OBJECT mode = (ARG_REF (2));
  98.     fast Tchannel channel =
  99.       ((mode == SHARP_F)
  100.        ? (OS_open_input_file (filename))
  101.        : (mode == SHARP_T)
  102.        ? (OS_open_output_file (filename))
  103.        : (OS_open_append_file (filename)));
  104.     OPEN_FILE_HOOK (channel);
  105.     PRIMITIVE_RETURN (long_to_integer (channel));
  106.   }
  107. }
  108.  
  109. DEFINE_PRIMITIVE ("FILE-LENGTH-NEW", Prim_file_length, 1, 1,
  110.   "Return the length of CHANNEL in characters.")
  111. {
  112.   PRIMITIVE_HEADER (1);
  113.   PRIMITIVE_RETURN (long_to_integer (OS_file_length (arg_channel (1))));
  114. }
  115.  
  116. DEFINE_PRIMITIVE ("FILE-POSITION", Prim_file_position, 1, 1,
  117.   "Return the position of CHANNEL's file-pointer.\n\
  118. This is a non-negative number strictly less than the file's length.")
  119. {
  120.   PRIMITIVE_HEADER (1);
  121.   PRIMITIVE_RETURN (long_to_integer (OS_file_position (arg_channel (1))));
  122. }
  123.  
  124. DEFINE_PRIMITIVE ("FILE-SET-POSITION", Prim_file_set_position, 2, 2,
  125.   "Set the file-pointer of CHANNEL to POSITION.\n\
  126. POSITION must be a non-negative number strictly less than the file's length.")
  127. {
  128.   PRIMITIVE_HEADER (1);
  129.   OS_file_set_position ((arg_channel (1)), (arg_nonnegative_integer (2)));
  130.   PRIMITIVE_RETURN (UNSPECIFIC);
  131. }
  132.